<script>
import {defineComponent} from 'vue'
import eventBus from "@/utils/eventBus";

export default defineComponent({
  name: "Main",
  data() {
    return {
      count: 0
    }
  },
  methods: {
    addCount(count) {
      this.count = count
    }
  },
  mounted() {
    // 组件挂载的时候使用eventBus.on("事件名",执行的回调函数)绑定事件
    eventBus.on("addCount", this.addCount)
  },
  unmounted() {
    // 组件挂载的时候使用eventBus.off("事件名",要销毁的回调函数名)关闭事件
    eventBus.off("addCount", this.addCount)
  }
})
</script>

<template>
  <div class="main">
    {{ count }}
  </div>
</template>

<style scoped lang="less">
.main {
  width: 100%;
  height: 100px;
  background-color: #f89106;
  display: flex;
  align-items: center;
  justify-content: center;
}
</style>
